package cn.dkk.structure_design.proxy.dynamic_proxy.jdk;

import cn.dkk.structure_design.proxy.pojo.SaleTickets;
import cn.dkk.structure_design.proxy.pojo.TranStation;

import java.lang.reflect.Proxy;

/**
 * @author dkk
 * @date 2022/7/10
 * @desc jdk动态代理
 */
public class ProxyFactory {

    private static TranStation target = new TranStation();

    public static SaleTickets getProxy(){
        // 通过Proxy.newProxyInstance 返回代理对象
        return (SaleTickets) Proxy.newProxyInstance(
                target.getClass().getClassLoader(),// 设置类加载器
                target.getClass().getInterfaces(),// 设置代理接口
                new TrainStationInvokeHandler(target)// 设置增强回调函数
        );
    }

}
